//
//  gamePlayer.m
//  my-BTB
//
//  Created by QuickSoluion on 9/7/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "gamePlayer.h"
#import "CotGio.h"
#import "BangHieu.h"
#import "XeKieu.h"
#import "reviewlayer.h"
#import "menuScene.h"
#import "SlideInLAnimation.h"
BOOL isDontTouchesAnyThing=FALSE;

BTBworld *_world;
CCSprite * _wBom;
CCSprite *_wMissle;
CCSprite * choiced;
int inumberBomWeapon=5;
int inumberMissleWeapon=2;

CCLabelTTF *_lbBom=nil;
CCLabelTTF *_lbMissle=nil;


CCLayer *tempLayer=nil;
CCLayer *tempBG=nil;
BOOL isChoiceWeapon=FALSE;
// click Bom no
CCSprite *disableImage=nil;
BOOL bClickBomflow=FALSE;
Character *_bom;

@implementation gamePlayer

-(void)initMap
{
	CCSprite *imagBG=[CCSprite spriteWithFile:@"garageMap1.png"];
	[imagBG setAnchorPoint:ccp(0,0)];
	imagBG.position=ccp(0,0);
	[self addChild:imagBG];
	// item more
	{
		CCSprite *imageItem=[CCSprite spriteWithFile:@"CotCau.png"];
		[imageItem setAnchorPoint:ccp(0,0)];
		imageItem.position=ccp(325,106);
		[self addChild:imageItem];
	}
	
	
		
}
-(id)init
{
	if ((self = [super init])) 
	{
		inumberBomWeapon=5;
		inumberMissleWeapon=3;
		
		self.isTouchEnabled = YES;	
		self.isAccelerometerEnabled = YES;
		[self initMap];
		_sizeMap = CGSizeMake(320+150, 480);
		_world=[[BTBworld alloc] initWithMap:1];				
		[self addChild:_world];
		
		[self initEntityByClassOfgamePlayer:[CotGio class]:ccp(450,210):1.0:NO];
		[self initEntityByClassOfgamePlayer:[BangHieu class]:ccp(592,168):1.0:NO];
		 
		_arraySpriteBom=[[NSMutableArray alloc] init];
		_arraySpriteMissle=[[NSMutableArray alloc] init];
		
		//[_world getTempGamePlayer:self];
		
	}
	return self;
}

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	if(isDontTouchesAnyThing==TRUE)
	{
		return;
	}
	
	
	if([[event allTouches] count] >1)
	{
		NSLog(@"dadsa");
		return;
	}

	UITouch *touch = [touches anyObject];
	CGPoint touchLocation = [touch locationInView: [touch view]];
	touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];	
	CGPoint pt = touchLocation;
	
	float alphaLechX=self.position.x;
	float alphaLechY=self.position.y;	
	
	CGRect rectPointBom= CGRectMake(_wBom.position.x-60, _wBom.position.y+60, 100, 100);
	CGRect rectPointMissle= CGRectMake(_wMissle.position.x-60, _wMissle.position.y+60, 100+100, 100);
	CGRect rectPointStarBom= CGRectMake(_bom.position.x-60, _bom.position.y+60, 100+100, 100);
	
	
	for(int i=0;i<[_arraySpriteBom count];i++)
	{
		CCSprite *image=(CCSprite*)[self getChildByTag:([[_arraySpriteBom objectAtIndex:i] intValue])];
		CGRect rectItem= CGRectMake(image.position.x-60+alphaLechX, image.position.y+60+alphaLechY, 100, 100);
		if([self isInside:rectItem :pt])
		{
			
			choiced=image;
			isChoiceWeapon=TRUE;
			return;
		}
	}
	for (int j=0; j<[_arraySpriteMissle count]; j++)
	{
		CCSprite *image=(CCSprite*)[self getChildByTag:([[_arraySpriteMissle objectAtIndex:j] intValue])];
		CGRect rectItem= CGRectMake(image.position.x-60+alphaLechX, image.position.y+60+alphaLechY, 100, 100);
		if([self isInside:rectItem :pt])
		{
			
			choiced=image;
			isChoiceWeapon=TRUE;
			return;
		}
	}
	
	
	
	
	
	bClickBomflow=TRUE;
	if(bClickBomflow==TRUE&&[self isInside:rectPointStarBom :pt])
	{
		NSLog(@"click StartBom");
		
		[self beginGame];
		[disableImage setVisible:TRUE];
		
	}
	else if([self isInside:rectPointBom :pt])
	{
		if(inumberBomWeapon<=0)
		{
			return ; /// hetBom xai
		}
		NSLog(@"get wBom");
		CCSprite * image=[CCSprite spriteWithFile:@"minnocham1.png"];
		image.position=ccpSub(_wBom.position, ccp(alphaLechX,alphaLechY)) ;//_wBom.position;//
		[self addChild: image z:1 tag:(10000+inumberBomWeapon)];
		[_arraySpriteBom addObject:[NSNumber numberWithInt:(10000+inumberBomWeapon)]];
		
		
		inumberBomWeapon--;
		
		[_lbBom setString:[NSString stringWithFormat:@"%d",inumberBomWeapon]];
		 
		choiced=image;
		isChoiceWeapon=TRUE;
		[disableImage setVisible:FALSE];
		 
		
	}
	else if([self isInside:rectPointMissle :pt])
	{
		if(inumberMissleWeapon<=0)
		{
			return ; /// het ten lua de xai
		}
		 NSLog(@"get missle");
		CCSprite * image=[CCSprite spriteWithFile:@"target.png"];
		image.position=ccpSub(_wMissle.position, ccp(alphaLechX,alphaLechY)) ;
		[self addChild: image z:1 tag:(15000+inumberMissleWeapon)];
		[_arraySpriteMissle addObject:[NSNumber numberWithInt:(15000+inumberMissleWeapon)]];// sua cho nay
		
		inumberMissleWeapon--;
		[_lbMissle setString:[NSString stringWithFormat:@"%d",inumberMissleWeapon]];
		
		 choiced=image;
		isChoiceWeapon=TRUE;
		[disableImage setVisible:FALSE];
	}
	
}
- (BOOL)isInside: (CGRect)rect: (CGPoint)p{
	NSLog(@"minx %8.3f", CGRectGetMinX(rect));
	NSLog(@"maxx %8.3f", CGRectGetMaxX(rect));
	NSLog(@"miny %8.3f", CGRectGetMinY(rect));
	NSLog(@"maxy %8.3f", CGRectGetMaxY(rect));
	
	if (CGRectGetMinX(rect) > p.x) {
		return FALSE;
	}
	if (CGRectGetMaxX(rect) < p.x) {
		return FALSE;
	}
	if (CGRectGetMinY(rect) < p.y) {
		return FALSE;
	}
	if (CGRectGetMaxY(rect) - 2 * rect.size.height > p.y) {
		return FALSE;
	}
	return TRUE;
}


-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	if(isDontTouchesAnyThing==TRUE)
	{
		return;
	}
	
	
	if(isChoiceWeapon==TRUE)
	{		
		
		UITouch *touch = [touches anyObject];
		CGPoint touchLocation = [touch locationInView: [touch view]];
		touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];	
		CGPoint pt = touchLocation;
		choiced.position=ccpSub(pt, ccp(self.position.x,self.position.y)) ;
		
		
	}
	else {
	
		switch ([[event allTouches] count])
		{
			case 1:
				// do scroll
				[self handleScrolling:touches];	
				[self applyFrameLimits];
				break;
			case 2:
				// do zoom
				break;
		}
		
	}
	
}

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	choiced=nil;
	isChoiceWeapon=FALSE;
	//[tempLayer setPosition:self.position];
}

- (void)handleScrolling:(NSSet *)touches {
	UITouch *touch = [touches anyObject];
	
	CGPoint touchLocation = [touch locationInView: [touch view]];	
	CGPoint prevLocation = [touch previousLocationInView: [touch view]];
	touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
	prevLocation = [[CCDirector sharedDirector] convertToGL: prevLocation];
	
	// subtract
	CGPoint diff = ccpSub(touchLocation,prevLocation);
	
	// add
	CGPoint tempPOS=self.position;
	CGPoint newpos = ccpAdd(self.position, diff);
	
	//NSLog(@"%8.3f - %8.3f", newpos.x, newpos.y);
	
	[self setPosition: newpos];
	
	
	
	
	
	int tempI=0;
	//int tempJ=0;
	if(tempPOS.x>newpos.x)
	{
		tempI=-1;
		//tempJ=1;
	}
	else
	{
		tempI=1;
		//tempJ=-1;
	}
	
	
	CGPoint tempBGnewpos = ccpAdd(tempBG.position, ccp(-tempI,0));
	[tempBG setPosition:tempBGnewpos];
	
	
	//NSLog(@"------%8.3f- %8.3f",diff.x,diff.y);
	
	CGPoint Animationnewpos = ccpAdd(tempLayer.position, ccp(tempI,0));
	
	[tempLayer setPosition:Animationnewpos];
	
	[self applyFrameLimitsbyLayer:tempLayer];
	[self applyFrameLimitsbyLayer:tempBG];
	 
}

- (void) applyFrameLimitsbyLayer:(CCLayer *)Layer
{
    //if (!scalable) { return; }
	
	CGSize size = CGSizeMake(320,480);//(1024, 768);
	
	// simsize
	CGSize contentSize = _sizeMap;		
	CGFloat simWidth = (Layer.scale)*contentSize.width;
	CGFloat simHeight = (Layer.scale)*contentSize.height;
	
	CGRect frameRect = CGRectMake(0, 0, size.width, size.height);
	CGSize contentSizeInSelfSpace = CGSizeMake(simWidth,simHeight);
	CGRect contentRect = CGRectMake(Layer.position.x, Layer.position.y, contentSizeInSelfSpace.width, contentSizeInSelfSpace.height);
	
	//[self zoomToCenterFit];
	
	CGFloat posX = Layer.position.x;
	CGFloat posY = Layer.position.y;
	
	
    if (CGRectGetMinX(contentRect) > CGRectGetMinX(frameRect)) { // check x
		posX = frameRect.origin.x;
		Layer.position = ccp(posX, posY);
		
    } else if (CGRectGetMaxX(contentRect) < CGRectGetMaxX(frameRect)){
		posX = CGRectGetMaxX(frameRect) - CGRectGetWidth(contentRect);
		Layer.position = ccp(posX, posY);
    }
    if (CGRectGetMinY(contentRect) > CGRectGetMinY(frameRect)) { // check y
		posY = frameRect.origin.y;
		Layer.position = ccp(posX, posY);
		
    } else if (CGRectGetMaxY(contentRect) < CGRectGetMaxY(frameRect)) {
		posY = CGRectGetMaxY(frameRect) - CGRectGetHeight(contentRect);
		Layer.position = ccp(posX, posY);
    }
	
    if (CGRectGetWidth(contentRect) < CGRectGetWidth(frameRect)) { // check width
		
		Layer.scale = CGRectGetWidth(frameRect) / contentSize.width;
		posX = frameRect.origin.x;
		Layer.position = ccp(posX, posY);
    }
    if (CGRectGetHeight(contentRect) < CGRectGetHeight(frameRect)) { // check height
        Layer.scale = CGRectGetHeight(frameRect) / contentSize.height;
		posY = frameRect.origin.y;
		Layer.position = ccp(posX, posY);
    }
	
}

- (void) applyFrameLimits {
    //if (!scalable) { return; }
	
	CGSize size = CGSizeMake(320,480);//(1024, 768);
	
	// simsize
	CGSize contentSize = _sizeMap;		
	CGFloat simWidth = (self.scale)*contentSize.width;
	CGFloat simHeight = (self.scale)*contentSize.height;
	
	CGRect frameRect = CGRectMake(0, 0, size.width, size.height);
	CGSize contentSizeInSelfSpace = CGSizeMake(simWidth,simHeight);
	CGRect contentRect = CGRectMake(self.position.x, self.position.y, contentSizeInSelfSpace.width, contentSizeInSelfSpace.height);
	
	//[self zoomToCenterFit];
	
	CGFloat posX = self.position.x;
	CGFloat posY = self.position.y;
	
	
    if (CGRectGetMinX(contentRect) > CGRectGetMinX(frameRect)) { // check x
		posX = frameRect.origin.x;
		self.position = ccp(posX, posY);
		
    } else if (CGRectGetMaxX(contentRect) < CGRectGetMaxX(frameRect)){
		posX = CGRectGetMaxX(frameRect) - CGRectGetWidth(contentRect);
		self.position = ccp(posX, posY);
    }
    if (CGRectGetMinY(contentRect) > CGRectGetMinY(frameRect)) { // check y
		posY = frameRect.origin.y;
		self.position = ccp(posX, posY);
		
    } else if (CGRectGetMaxY(contentRect) < CGRectGetMaxY(frameRect)) {
		posY = CGRectGetMaxY(frameRect) - CGRectGetHeight(contentRect);
		self.position = ccp(posX, posY);
    }
	
    if (CGRectGetWidth(contentRect) < CGRectGetWidth(frameRect)) { // check width
		
		self.scale = CGRectGetWidth(frameRect) / contentSize.width;
		posX = frameRect.origin.x;
		self.position = ccp(posX, posY);
    }
    if (CGRectGetHeight(contentRect) < CGRectGetHeight(frameRect)) { // check height
        self.scale = CGRectGetHeight(frameRect) / contentSize.height;
		posY = frameRect.origin.y;
		self.position = ccp(posX, posY);
    }
	
}

-(Character*)initEntityByClassOfgamePlayer:(Class)tempC:(CGPoint)p:(float)fScale:(BOOL)yes_noScale
{
	Character* _itemClass=[[[tempC alloc] initWithParent:self] autorelease];
	
	if(yes_noScale==YES)
	{
		[_itemClass setScale:fScale];
	}
	_itemClass.position = p	;				
	id Action = [_itemClass createAnimation];
	[_itemClass runAction:Action];
	
	return _itemClass;
	
}




-(void)beginGame
{
	// bom
	for (int i=0;i<[_arraySpriteBom count]; i++) 
	{
		CCSprite *image=(CCSprite*)[self getChildByTag:([[_arraySpriteBom objectAtIndex:i] intValue])];
	 
		NSLog(@"%8.3f- %8.3f",image.position.x,image.position.y);
	 
		[_world SetupBomb:image.position ];
		[self removeChildByTag:[[_arraySpriteBom objectAtIndex:i] intValue] cleanup:TRUE];
	 
	 }
	 [_arraySpriteBom removeAllObjects];
	 
	
	for (int j=0; j<[_arraySpriteMissle count]; j++) {
		CCSprite *image=(CCSprite*)[self getChildByTag:([[_arraySpriteMissle objectAtIndex:j] intValue])];		
		NSLog(@"%8.3f- %8.3f",image.position.x,image.position.y);
		
		[_world settupMissle:ccp(image.position.x,300) ];
		[self removeChildByTag:[[_arraySpriteMissle objectAtIndex:j] intValue] cleanup:TRUE];
	}
	[_arraySpriteMissle removeAllObjects];
	
	
}

-(void)dealloc
{
	[super dealloc];
	//[_arraySpriteBom release];
	//[_arraySpriteMissle release];
}
@end



















@implementation staticBGLayer
-(id)init
{
	if ((self = [super init])) 
	{
		CCSprite *imagBG=[CCSprite spriteWithFile:@"bgmap1.png"];
		[imagBG setAnchorPoint:ccp(0,0)];
		imagBG.position=ccp(0,0);
		[self addChild:imagBG];
		
		
		
		
	}
	return self;
}

@end


@implementation MainBGLayer 

-(id)init
{
	if ((self = [super init])) 
	{
		_lenghtMay1=0;
		_lenghtMay2=0;
		_lenghtMay3=0;
		bMay1TurnRL=TRUE;
		bMay2TurnRL=TRUE;
		bMay3TurnRL=TRUE;
		CCSprite *imagBG=[CCSprite spriteWithFile:@"bgmap1.png"];
		[imagBG setAnchorPoint:ccp(0,0)];
		imagBG.position=ccp(0,0);
		[self addChild:imagBG];
		
		_may1=[CCSprite spriteWithFile:@"may4.png"];
		[_may1 setAnchorPoint:ccp(0,0)];
		_may1.position=ccp(250,150);
		[self addChild:_may1];
		
		_may2=[CCSprite spriteWithFile:@"may5.png"];
		[_may2 setAnchorPoint:ccp(0,0)];
		_may2.position=ccp(50,120);
		[self addChild:_may2];
		
		_may3=[CCSprite spriteWithFile:@"may6.png"];
		[_may3 setAnchorPoint:ccp(0,0)];
		_may3.position=ccp(250,170);
		[self addChild:_may3];
		
		image1nuoc=[CCSprite spriteWithFile:@"nuoc.png"];
		[image1nuoc setAnchorPoint:ccp(0,0)];
		image1nuoc.position=ccp(0,0);
		[self addChild:image1nuoc];
		
		image2nuoc=[CCSprite spriteWithFile:@"nuoc.png"];
		[image2nuoc setAnchorPoint:ccp(0,0)];
		image2nuoc.position=ccp(640,0);
		[self addChild:image2nuoc];
		
		
		[self schedule: @selector(CloudFly) interval:1.0/20.0];
		
		[self schedule: @selector(waterRun) interval:1.0/60.0];		
				
	}
	return self;
}

-(void)CloudFly
{
	if(bMay1TurnRL==TRUE)
	{
		_lenghtMay1-=1;
		_may1.position =ccp(_may1.position.x-1,_may1.position.y);
		if(_lenghtMay1 <-270)
		{
			bMay1TurnRL=FALSE;
			
		}
	}
	else {
		_lenghtMay1+=1;
		_may1.position =ccp(_may1.position.x+1,_may1.position.y);
		if(_lenghtMay1>200)
		{
			
			bMay1TurnRL=TRUE;
			
		}
	}

	if(bMay2TurnRL==TRUE)
	{
		
		_lenghtMay2-=1;
		_may2.position =ccp(_may2.position.x+2,_may2.position.y);
		if(_lenghtMay2 <-270)
		{
			bMay2TurnRL=FALSE;
			
		}
	}
	else {
		_lenghtMay2+=1;
		_may2.position =ccp(_may2.position.x-2,_may2.position.y);
		if(_lenghtMay2>170)
		{
			
			bMay2TurnRL=TRUE;
			
		}
	}
	
	
	
}
-(void)waterRun
{
	int X_1=image1nuoc.position.x;	
	int X_2=image2nuoc.position.x;
	
	
	if(X_1<-640)
	{
		X_1=639;
	}
	
	if(X_2<-640)
	{
		X_2=639;
	}
	
	X_1=X_1-1;
	X_2=X_2-1;
	
	
	image1nuoc.position=ccp(X_1,image1nuoc.position.y);
	image2nuoc.position=ccp(X_2,image1nuoc.position.y);
}



@end

@implementation bgAnimationLayer 

-(id)init
{
	if ((self = [super init])) 
	{
		itemTauThuy=nil;
		bTurnRL=TRUE;
		_lenghtRun=0;
		
		itemTauThuy=[self initEntityByClass:[TauThuy class]:ccp(200,42):1.0:NO];
		
		[self schedule: @selector(tauthuyRun) interval:1.0/20.0];

	}
	return self;
}

-(void)tauthuyRun
{
	if(itemTauThuy==nil)
	{
		return;
	}
	
	if(bTurnRL==TRUE)
	{
		_lenghtRun-=1;
		itemTauThuy.position =ccp(itemTauThuy.position.x-1,itemTauThuy.position.y);
		if(_lenghtRun <-210)
		{
			[itemTauThuy setFlipX:TRUE];
			bTurnRL=FALSE;
			
		}
	}  
	else {
		_lenghtRun+=1;
		itemTauThuy.position =ccp(itemTauThuy.position.x+1,itemTauThuy.position.y);
		if(_lenghtRun>80)
		{
			[itemTauThuy setFlipX:TRUE];
			bTurnRL=TRUE;
			
		}
	}

}


-(Character*)initEntityByClass:(Class)tempC:(CGPoint)p:(float)fScale:(BOOL)yes_noScale
{
	Character* _itemClass=[[[tempC alloc] initWithParent:self] autorelease];
	
	if(yes_noScale==YES)
	{
		[_itemClass setScale:fScale];
	}
	_itemClass.position = p	;				
	id Action = [_itemClass createAnimation];
	[_itemClass runAction:Action];
	
	return _itemClass;
	
}
@end


@implementation GameControlLayer

-(id) init
{
	if( (self=[super init])) {	
			
		isDontTouchesAnyThing=TRUE;
		_staticBG=[staticBGLayer node];		
		[self addChild:_staticBG z:0];
		
		
		_gameLayer=[gamePlayer node];
		[self addChild:_gameLayer z:3];
		
		_bgAnimation=[bgAnimationLayer node];
		[self addChild:_bgAnimation z:2];
		tempLayer=_bgAnimation;
		
		_mainBG=[MainBGLayer node];		
		[self addChild:_mainBG z:1];
		tempBG=_mainBG;
	
		_tempCharacterCar=[self initEntityByClassOfgameControlPlayer:[XeKieu class]:ccp(0,125):0.2:YES];
		
		[self settupCarRunAndBeginControl];
		
		
		
				
	}
	return self;
}

-(void)settupCarRunAndBeginControl
{
	NSMutableArray* actionList = [[NSMutableArray alloc] initWithCapacity:1];
	
	for (int i=0; i<45; i++) {
		[actionList addObject:[CCCallFunc actionWithTarget:self selector:@selector(carMoving)]];
		[actionList addObject:[CCDelayTime actionWithDuration:(0.1f)]];
	}
	[actionList addObject:[CCCallFunc actionWithTarget:self selector:@selector(removeCarAnimationAndAddCarSpysic)]];
	[actionList addObject:[CCCallFunc actionWithTarget:self selector:@selector(addControlMenu)]];
	
	CCFiniteTimeAction* seq = [self getActionSequence:actionList];	
	[actionList release];			
	[self runAction:seq];
	
}
-(void)carMoving
{
	if(_tempCharacterCar==nil)
	{
		return;
	}
	
	
	_tempCharacterCar.position=ccp(_tempCharacterCar.position.x+4,_tempCharacterCar.position.y);
	
}
-(void)removeCarAnimationAndAddCarSpysic
{
	CGPoint p=_tempCharacterCar.position;
	
	[_tempCharacterCar removeFromParentAndCleanup:TRUE];
	[_world SetupCarAt:ccp(p.x+4,p.y-15)];
	[_world StartSpysic];
	isDontTouchesAnyThing=FALSE;

	
}

-(void)settUpEnableClick
{
	isDontTouchesAnyThing=FALSE;
}
-(void)addControlMenu
{
	[self clearCache];
	
	_rvLayer=[reviewlayer node];
	[_rvLayer setAnchorPoint:ccp(0,0)];
	_rvLayer.position=ccp(0,0);
	[self addChild:_rvLayer z:90000];
	[_rvLayer setVisible:FALSE];
	[_rvLayer getInstanceGameControler:self];
	
	/// init weapon
	
	_wBom=[CCSprite spriteWithFile:@"minnocham1.png"];
	[_wBom setAnchorPoint:ccp(0,0)];
	_wBom.position=ccp(20,275);
	[self addChild:_wBom z:100];
	
	_wMissle=[CCSprite spriteWithFile:@"rocket.png"];
	[_wMissle setAnchorPoint:ccp(0,0)];
	_wMissle.position=ccp(50,275);
	[self addChild:_wMissle z:100];
	
	_bom=[self initEntityByClassOfgameControlPlayer:[Bom class]:ccp(440,240):1.0:NO];
	
	disableImage=[CCSprite spriteWithFile:@"Disable_Image.png"];
	[disableImage setAnchorPoint:ccp(0,0)];
	disableImage.position=ccp(430,220);
	[self addChild:disableImage z:10000];
	
	
	CCMenu *_menu=[CCMenu menuWithItems:nil];
	CCMenuItemImage *item=[CCMenuItemImage itemFromNormalImage:@"btPause.png" selectedImage:@"btPause_hover.png" disabledImage:@"btPause.png" target:self selector:@selector(callMenuGame)]; 
	[item setScale:1.4f];
	[_menu addChild:item];
	[_menu setAnchorPoint:ccp(0,0)];
	_menu.position=ccp(450,300);
	[self addChild:_menu z:100];
	
	
	
	
	
	_menuSpecial=[CCMenu menuWithItems:nil];
	
	CCMenuItemImage *item2=[CCMenuItemImage itemFromNormalImage:@"refresh.png" selectedImage:@"refresh_hover.png" disabledImage:@"refresh.png" target:self selector:@selector(refeshGame)]; 
	item2.position=ccp(420,190);
	CCMenuItemImage *item3=[CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back_hover.png" disabledImage:@"back.png" target:self selector:@selector(quitGame)];
	item3.position=ccp(420,80);
	
	[_menuSpecial addChild:item2];
	[_menuSpecial addChild:item3];
	[_menuSpecial setAnchorPoint:ccp(0,0)];
	_menuSpecial.position=ccp(0,0);
	
	[self addChild:_menuSpecial z:900000];
	
	[_menuSpecial setVisible:FALSE];
	
	
	
	_lbBom=[CCLabelTTF labelWithString:[NSString stringWithFormat:@"%d",inumberBomWeapon] fontName:@"Arial" fontSize:20];
	[_lbBom setColor:ccRED];
	[_lbBom setAnchorPoint:ccp(0,0)];
	_lbBom.position=ccp(30,250);
	[self addChild:_lbBom z:900000];
		
	_lbMissle=[CCLabelTTF labelWithString:[NSString stringWithFormat:@"%d",inumberMissleWeapon] fontName:@"Arial" fontSize:20];
	[_lbMissle setColor:ccRED];
	[_lbMissle setAnchorPoint:ccp(0,0)];
	_lbMissle.position=ccp(80,250);
	[self addChild:_lbMissle z:900000];
	
}
-(void)refeshGame
{
	//[_gameLayer releaseTwoArray];
	[self removeAllChildrenWithCleanup:TRUE];
	[[CCDirector sharedDirector] replaceScene:[GameControlLayer node]];
}
-(void)quitGame
{
	[self changetoMenuGame];
}

-(void)callMenuGame
{
	isDontTouchesAnyThing=TRUE;
	[_rvLayer setVisible:TRUE];
	[_menuSpecial setVisible:TRUE];
}


-(void)resetgame
{
	
}

-(void)dealloc
{
	[super dealloc];
	
}
-(Character*)initEntityByClassOfgameControlPlayer:(Class)tempC:(CGPoint)p:(float)fScale:(BOOL)yes_noScale
{
	Character* _itemClass=[[[tempC alloc] initWithParent:self] autorelease];
	
	if(yes_noScale==YES)
	{
		[_itemClass setScale:fScale];
	}
	_itemClass.position = p	;				
	id Action = [_itemClass createAnimation];
	[_itemClass runAction:Action];
	
	return _itemClass;
	
}

- (void) clearCache
{
	[[CCTextureCache sharedTextureCache] removeUnusedTextures];
	[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
}

-(CCFiniteTimeAction *) getActionSequence: (NSMutableArray *) actions
{
	CCFiniteTimeAction *seq = nil;
	for (CCFiniteTimeAction *anAction in actions)
	{
		if (!seq)
		{
			seq = anAction;
		}
		else
		{
			seq = [CCSequence actionOne:seq two:anAction];
		}
	}
	return seq ;
	
}

-(void)changetoMenuGame
{
	
	[[CCDirector sharedDirector] replaceScene:[SlideInLAnimation transitionWithDuration:2.0f scene:[menuScene node]]];
}

@end